<template>
	<view>
		<view class="nav bg-gradual-green">
			<image src="/static/logo.png" class="logo" mode="widthFix"></image>
			<view style="margin: 0 34upx;font-size: 38upx;color: #fff;margin-top: 240upx;height: 70upx;line-height: 70upx;">
				您好 !
			</view>
			<view style="margin: 0 34upx;font-size: 44upx;color: #fff;">
				欢迎回来
			</view>
		</view>
		
		<view class="content">
			<view class="webkit input" style="margin-top: 100upx;">
				<image src="/static/login/phone.png"></image>
				<input class="flex" type="text" v-model="account" placeholder-style="color:#aaa" placeholder="请输入您的用户名"/>
			</view>
			<view class="webkit input">
				<image src="/static/login/pwd.png"></image>
				<input class="flex" type="text" placeholder-style="color:#aaa" v-model="password" password  placeholder="请输入您的密码"/>
			</view>
			<button type="" class="login-btn bg-gradual-green" :loading="loading" @click="login">登录</button>
		</view>
		
		<!-- <view class="forget-section" @click="tohome">
			随便逛逛
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				account:'',
				password:'',
				loading:false,
				openid:[],
				error:'',
			};
		},
		// onBackPress(options) { // 控制顶部返回跳转到指定页面
		// 	this.back();  
		// 	return true;  
		// },  
		methods: {
			async login() {
				var o = this
				this.loading = true
				if(this.account == ""){
					this.loading=false
					uni.showToast({
						title: '请输入用户名',
						icon:"none"
					});
				}else if(this.password == ""){
					this.loading = false
					uni.showToast({
						title: '请输入密码',
						icon:"none"
					});
				}else{
				var data = {
						'account': this.account,
						'password': this.password,
					}
					console.log(JSON.stringify(data))
					// https://jxjsservice.jxfit.cn  // https://jxjsservice.jxfit.cn
					let res = await this.$myRuquest({
						url: "/coach/user/login",
						method: 'POST',
						data,
					})
					
					if ( res.data.result == 200 ) {
						let gymList = res.data.datas.gymList;
						let gymId = gymList[0].
						gymList = { ...gymList } // 数组转对象
						uni.setStorage({
							key: 'gymList',
							data: gymList
						})
						uni.setStorage({
							key: 'gymId',
							data: gymId
						})
						uni.setStorage({
							key: 'openid',
							data: res.data.datas.id
						})
						uni.setStorage({
							key: 'avatar',
							data: res.data.datas.headPortrait
						})
						uni.setStorage({
							key: 'userName',
							data: res.data.datas.userName
						})
						setTimeout(()=>{
							o.loading = false
							uni.redirectTo({
								url: '/pages/index/index',
								// /pages/index/index?path=user
							})
						},700)
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				}
			},
			back(){
				uni.reLaunch({
					url: '/pages/page/page'
				});
			},
			tohome () {
				uni.navigateTo({
					url: '../../pages/index/index'
				})
			},
			jump(e){
				uni.navigateTo({
					url: e.currentTarget.dataset.src
				});
			},
		}
	}
</script>

<style lang="scss">
	page {background-color:#fff;}
	.forget-section{
		font-size: 26upx;
		color: #39bb9e;
		text-align: center;
		margin-top: 40upx;
	}
	.webkit {display: flex;}
	.nav {width: 100%;height: 500upx;position: relative;overflow: hidden;}
	.logo {display:block;position: absolute;right: 30upx;top: 160upx;width: 160upx;}
	.content {width:100%;height: 500upx;border-radius: 60upx 60upx 0 0;overflow: hidden;position: relative;margin-top: -60upx;background: #fff;}
	.input {border-bottom:1px solid #f0f0f0;margin:0 30upx;}
	.input image {width:50upx;height:50upx;margin-left:20upx;margin-right:10upx;margin-top:15upx;}
	.input input {line-height:80upx;font-size:28upx;height:80upx;}
	button {margin:60upx 30upx 20upx;}
	.login-btn {color: #fff;}
</style>
